var data;
Ext.define('NIM.view.AssetDataMaster.AssetTowerForm', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.AssetTowerForm',
    id: 'assetTowerPanel',
    autoScroll: true,
    items: [
        {
            xtype: 'form', // category info
            id: 'assetCatInfoForm',
            url: '#',
            listeners: {
                afterrender: function () {
        	  		Ext.getStore('AssetDataMaster.TowerCompany').removeAll();
                    Ext.getStore('AssetDataMaster.TowerCompany').load();
                
                    Ext.getCmp('siteIdInfo').setValue(site_id);
                    Ext.Ajax.request({
                        method: "GET",
                        dataType: "json",
                        url: "./Services/DataMaster/AssetCategory?CATEGORY=" + category,
                        async: false,
                        success: function (c) {
                            var jsonResults = $.parseJSON(c.responseText);
                            data = jsonResults.item[0];
                            Ext.getCmp('assetCatInfoForm').getForm().setValues(data);

                        }
                    });
                    
                }

            },
            items: [
                {
                    xtype: 'textfield',
                    disabled: true,
                    cls: 'black',
                    id: 'siteIdInfo',
                    margin: '5 10 5 25',
                    labelWidth: 100 / 1366 * screen.width,
                    width: 650 / 1366 * screen.width,
                    fieldLabel: 'Site ID',
                    msgTarget: 'title',
                    allowBlank: true,
                    validateBlank: false

                },
                {
                    xtype: 'textfield',
                    disabled: true,
                    cls: 'black',
                    name: 'CATEGORY',
                    margin: '5 10 5 25',
                    labelWidth: 100 / 1366 * screen.width,
                    width: 650 / 1366 * screen.width,
                    fieldLabel: 'Asset Category',
                    msgTarget: 'title',
                    allowBlank: true,
                    validateBlank: false

                },
                {
                    xtype: 'textfield',
                    disabled: true,
                    cls: 'black',
                    name: 'DESCRIPTION',
                    margin: '5 10 5 25',
                    labelWidth: 100 / 1366 * screen.width,
                    width: 650 / 1366 * screen.width,
                    fieldLabel: 'Description',
                    msgTarget: 'title',
                    allowBlank: true,
                    validateBlank: false

                }
            ]

        }, // end form category info			
        {
            xtype: 'form', // asset form
            id: 'assetTowerForm',
            method: 'POST',
            url: './Services/Asset/AssetTower/Update/',
            listeners: {
                afterrender: function () {
                	  //test
                    //Ext.getCmp('assetTowerForm').query('.field, .button').forEach(function(c){c.setDisabled(true);});

                    Ext.Ajax.request({
                        method: "GET",
                        dataType: "json",
                        url: "./Services/DataMaster/AdditionalField/List/" + category,
                        async: false,
                        success: function (c) {
                            var jsonResults = $.parseJSON(c.responseText);
                            Ext.getCmp('additionalInformationId').add(jsonResults);
                        }
                    });

                    Ext.Ajax.request({
                        method: "GET",
                        dataType: "json",
                        url: "./Services/Asset/AssetSACDetails?cat=" + category + "&siteid=" + site_id + "",
                        async: false,
                        success: function (c) {
                            var jsonResults = $.parseJSON(c.responseText);
                            data = jsonResults.item[0];
                            Ext.getCmp('assetTowerForm').getForm().setValues(data);
                        }
                    });
                    
                    Ext.getCmp('siteIdHidden').setValue(site_id); //bisa jadi error
                                        
                    var assetId = Ext.getCmp("assetIdTower").getValue();
					Ext.getStore('AssetDataMaster.AssetTowerContract').removeAll();
					Ext.getStore('AssetDataMaster.AssetTowerContract').getProxy().url = './Services/Asset/AssetTowerContract/List?assetId=' + assetId;
					Ext.getStore('AssetDataMaster.AssetTowerContract').load();
					Ext.getStore('AssetDataMaster.AssetTowerContract').on({
						load:function(){
							var store = Ext.getStore('AssetDataMaster.AssetTowerContract').getAt(0);
							if(store != null){
								Ext.getCmp('docskrpd').setValue(store.get('CONTRACT_NO'));
							}
						}
					});
									
                    Ext.getStore('AssetDataMaster.AssetTowerImb').removeAll();
					Ext.getStore('AssetDataMaster.AssetTowerImb').getProxy().url = './Services/Asset/AssetTowerImb/List?assetId=' + assetId;
					Ext.getStore('AssetDataMaster.AssetTowerImb').load();
					Ext.getStore('AssetDataMaster.AssetTowerImb').on({
						load:function(){
							var store = Ext.getStore('AssetDataMaster.AssetTowerImb').getAt(0);
							if(store != null){
								Ext.getCmp('docimb').setValue(store.get('IMB_NO'));
							}
							
						}
					});

					var flag = Ext.getCmp('assettelkomseltower').getValue();
            		if(flag == "True"){
                		Ext.getCmp('ownernama').setValue('0');
            		}else {
                		Ext.getCmp('ownernama').setValue('null');
            		}  
                }
            },
            items: [
                {
                    xtype: 'hiddenfield',
                    cls: 'black',
                    id: 'assetIdTower',
                    name: 'ASSET_DETAIL_ID',
                    margin: '5 10 5 25',
                    labelWidth: 100 / 1366 * screen.width,
                    width: 355 / 1366 * screen.width,
                    fieldLabel: 'Site ID',
                    msgTarget: 'title',
                    allowBlank: true,
                    validateBlank: false

                },
                {
                    xtype: 'hiddenfield',
                    cls: 'black',
                    id: 'siteIdHidden',
                    name: 'SITE_ID',
                    margin: '5 10 5 25',
                    labelWidth: 100 / 1366 * screen.width,
                    width: 355 / 1366 * screen.width,
                    fieldLabel: 'Site ID',
                    msgTarget: 'title',
                    allowBlank: true,
                    validateBlank: false

                },
                {
                    xtype: 'fieldset',
                    columnWidth: 0.5,
                    title: 'Inventory Information',
                    width: 780 / 1366 * screen.width,
                    heigth: 130,
                    margin: '0 10 5 10',
                    items: [{
                            xtype: 'panel',
                            border: false,
                            layout: {
                                type: 'table',
                                columns: 2
                            },
                            items: [{
                                    xtype: 'panel',
	                                width: 380 / 1366 * screen.width,
                                    height: 140,
                                    border: false,
                                    margin: '0 10 0 0',
                                    items: [
                                        {
                                            xtype: 'textfield',
                                            cls: 'black',
                                            id: 'skutower',
                                            name: 'SKU_NUMBER',
                                            margin: '0 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'SKU',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            cls: 'black',
                                            id: 'serialnumbertower',
                                            name: 'SERIAL_NUMBER',
                                            margin: '5 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Serial No',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            cls: 'black',
                                            id: 'ponumbertower',
                                            name: 'PO_NUMBER',
                                            margin: '5 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Post No',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            cls: 'black',
                                            id: 'basttower',
                                            name: 'BAST',
                                            margin: '5 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'BAST',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false
                                        },
                                        {
                                            xtype: 'combobox',
                                            cls: 'black',
                                            id: 'statusactivetower',
                                            name: 'STATUS',
                                            margin: '5 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Status',
                                            store: [['ACTIVE', 'ACTIVE'], ['INACTIVE', 'INACTIVE']],
                                            msgTarget: 'title',
                                            allowBlank: false
                                        }
                                    ]
                                },
                                {
                                    xtype: 'panel',
	                                width: 380 / 1366 * screen.width,
                                    border: false,
                                    height: 140,
                                    items: [
                                        {
                                            xtype: 'combobox',
                                            cls: 'black',
                                            id: 'assettelkomseltower',
                                            name: 'ASSET_FLAG',
                                            margin: '0 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Asset Telkomsel',
                                            store: [['True', 'Yes'], ['False', 'No']],
                                            msgTarget: 'title',
                                            allowBlank: false,
                                            listeners : {
                                    			select : function (obj, newValue, oldValue, eOpts) {
                                            		var flag = Ext.getCmp('assettelkomseltower').getValue();
                                            		if(flag == "True"){
	                                            		Ext.getCmp('ownernama').setValue('0');
                                            		}else {
	                                            		Ext.getCmp('ownernama').setValue('null');
                                            		}                                            		
                                            	}
                                            
                                    		}
                                    
                                        },
                                        {
                                            xtype: 'textfield',
                                            cls: 'black',
                                            id: 'partnotower',
                                            name: 'PART_NUMBER',
                                            margin: '5 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Part No',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false
                                        },
                                        {
                                            xtype: 'panel',
                                            border: false,
                                            height: 20

                                        },
                                        {
                                            xtype: 'textfield',
                                            cls: 'black',
                                            id: 'porcvnumbertower',
                                            name: 'RCV_NUMBER',
                                            margin: '5 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Po Rcv No',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            cls: 'black',
                                            id: 'referencetower',
                                            name: 'REFERENCE',
                                            margin: '5 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Reference',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false
                                        }]

                                }]


                        }]
                },
                {
                    xtype: 'fieldset',
                    columnWidth: 0.5,
                    title: 'Tower Information',
                    width: 780 / 1366 * screen.width,
                    heigth: 110,
                    margin: '0 10 5 10',
                    items: [{
                            xtype: 'panel',
                            border: false,
                            layout: {
                                type: 'table',
                                columns: 2
                            },
                            items: [{
                                    xtype: 'panel',
	                                width: 380 / 1366 * screen.width,
                                    height: 115,
                                    border: false,
                                    margin: '0 10 0 0',
                                    items: [{
                                            xtype: 'combobox',
                                            cls: 'black',
                                            id: 'towertype',
                                            name: 'DESCRIPTION',
                                            margin: '0 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Tower Type',
                                            msgTarget: 'title',
                                            allowBlank: true
                                        },
                                        {
                                            xtype: 'combobox',
                                            cls: 'black',
                                            id: 'towerposition',
                                            name: 'TOWER_POSITION',
                                            margin: '0 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Tower Position',
                                            msgTarget: 'title',
                                            allowBlank: true
                                        },
                                        {
                                            xtype: 'combobox',
                                            cls: 'black',
                                            id: 'imbstatus',
                                            name: 'TOWER_IMB_STATUS',
                                            margin: '0 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'IMB Status',
                                            msgTarget: 'title',
                                            allowBlank: true
                                        },
                                        {
                                            xtype: 'combobox',
                                            cls: 'black',
                                            id: 'ownership',
                                            name: 'TOWER_OWNERSHIP',
                                            margin: '0 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Ownership',
                                            msgTarget: 'title',
                                            allowBlank: true
                                        }]
                                },
                                {
                                    xtype: 'panel',
	                                width: 380 / 1366 * screen.width,
                                    border: false,
                                    height: 115,
                                    items: [{
                                            xtype: 'textfield',
                                            cls: 'black',
                                            id: 'towerheight',
                                            name: 'TOWER_HEIGHT',
                                            margin: '0 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Tower Height',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false
                                        },
                                        {
                                            xtype: 'combobox',
                                            cls: 'black',
                                            id: 'satuandaya',
                                            name: 'POWER_SUPPLY_TYPE',
                                            margin: '0 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Satuan Daya',
                                            msgTarget: 'title',
                                            allowBlank: true
                                        },
                                        {
                                            xtype: 'textfield',
                                            cls: 'black',
                                            id: 'satuanterpasang',
                                            name: 'POWER_SUPPLY_INSTALLED',
                                            margin: '5 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Daya Terpasang',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false
                                        },
                                        {
                                            xtype: 'combobox',
                                            cls: 'black',
                                            id: 'ownernama',
                                            name: 'TOWER_OWNER',
                                            margin: '5 10 5 5',
                                            labelWidth: 100 / 1366 * screen.width,
                                            width: 355 / 1366 * screen.width,
                                            fieldLabel: 'Owner Name',
                                            msgTarget: 'title',
                                            allowBlank: true,
                                            validateBlank: false,
	                                        displayField: 'TOWER_COMPANY_NAME',
	                                        valueField: 'TOWER_COMPANY_ID',
	                                        emptyText: 'Owner Name',
	                                        queryMode: "local",
	                                        forceSelection: true,
	                                        store: 'AssetDataMaster.TowerCompany'
                                        }]

                                }]


                        }]
                },
                {
                    xtype: 'panel',
                    width: 780 / 1366 * screen.width,
                    border: false,
                    layout: 'hbox',
                    items: [{
                            xtype: 'fieldset',
                            columnWidth: 0.5,
                            title: 'Tower Document',
                            width: 380 / 1366 * screen.width,
                            height: 80,
                            margin: '0 10 5 10',
                            items: [
                                {
                                	xtype: 'panel',
	                                width: 380 / 1366 * screen.width,
	                                heigth: 80,
	                                layout: 'hbox',
	                                border: false,
	                                margin: '0 10 0 0',
	                                items: [
	                                {
	                                	xtype: 'textfield',
	                                    cls: 'black',
	                                    id: 'docskrpd',
    	                                margin: '0 0 0 5',
	                                    labelWidth: 100 / 1366 * screen.width,
	                                    width: 290 / 1366 * screen.width,
	                                    fieldLabel: 'Doc. SKRD/RPM',
	                                    msgTarget: 'title',
	                                    allowBlank: true,
	                                    validateBlank: false
	                                },
	                                {
                                        xtype: 'button',
                                        width: 50,
    	                                margin: '0 0 0 5',
                                        text: 'Upload',
                                        id: 'btnUploadTowContract',
                                        handler: function () {
                                    		popupTowerContract();
                                        }
                                    }
	                                ]
                                },
                                {
                                	xtype: 'panel',
	                                width: 380 / 1366 * screen.width,
	                                heigth: 80,
	                                layout: 'hbox',
	                                border: false,
	                                margin: '0 10 0 0',
	                                items: [
	                                {
	                                    xtype: 'textfield',
	                                    cls: 'black',
	                                    id: 'docimb',
    	                                margin: '0 0 0 5',
	                                    labelWidth: 100 / 1366 * screen.width,
	                                    width: 290 / 1366 * screen.width,
	                                    fieldLabel: 'Doc. IMB',
	                                    msgTarget: 'title',
	                                    allowBlank: true,
	                                    validateBlank: false
	                                },
	                                {
                                        xtype: 'button',
                                        width: 50,
    	                                margin: '0 0 0 5',
                                        text: 'Upload',
                                        id: 'btnUploadTowImb',
                                        handler: function () {
                                    		popupTowerImb();
                                        }
                                    }
	                                ]

                                }
                            ]

                        },
                        {
                            xtype: 'panel',
                            border: false,
                            items: [
                                {
                                    xtype: 'fieldset',
                                    id: 'additionalInformationId',
                                    columnWidth: 0.5,
                                    title: 'Additional Information',
	                                width: 380 / 1366 * screen.width,
                                    margin: '0 0 5 5',
                                },
                                {
                                    xtype: 'button',
                                    width: 60,
                                    height: 30,
                                    margin: '0 0 0 5',
                                    text: 'Update',
                                    id: 'btnUpdateTower',
                                    handler: function () {
                                        this.up('form').getForm().submit({
                                            success: function (form, action) {
                                                Ext.Msg.alert('Submited', action.response.responseText);
                                            },
                                            failure: function (form, action) {
                                                Ext.Msg.alert('Submited', action.response.responseText);
                                            }

                                        });
                                    }

                                },
                                {
                                    xtype: 'button',
                                    id: 'btnCancelTower',
                                    width: 60,
                                    height: 30,
                                    margin: '0 0 0 10',
                                    text: 'Cancel',
                                    handler: function () {
                                        this.up('form').getForm().setValues(data);
                                    }

                                },
        		                {
        		                    xtype: 'button',
        		                    text: 'EXPORT TO PDF',
        		                    icon : 'images/pdf-icon-btn.png',
                                    width: 105,
                                    height: 30,
                                    margin: '0 0 0 20',
        		                    handler: function () {
        	                			location.href = pdf+""+site_id;
        		                    }
        		                },
        		                {
        		                    xtype: 'button',
        		                    text: 'EXPORT TO EXCEL',
        		                    icon : 'images/Excel-icon-btn.png',
                                    width: 105,
                                    height: 30,
                                    margin: '0 0 0 10',
        		                    handler: function () {
        		                		location.href = xls+""+site_id;
        		                    }
        		                }

                            ]
                        }
                    ]
                }
            ]
        }// end asset tower form

    ] // end panel items

});